class ItemsController < ApplicationController

  def new
    @item = Item.new
    @user = User.find(session[:user])
  end
  
  def index
     @items = Item.all
  end
  
  def edit
     @items = Item.all
  end
  
  def show
    @item = Item.find(params[:id])
  end
  
  def create
    if request.post?
        @item = Item.new(params[:item])
        @item.user = @user
        if @item.save
            flash[:success] = "you've succefully created a new item"
            redirect_to items_path
        else
            flash[:error] = "Couldn't create new item, please try again."
            redirect_to :action => :new
        end
    end
  end
  
end
